﻿
@{
    ViewBag.Title = "SetProduct";
    Layout = "~/Views/Shared/_Window.cshtml";
}

@model IEnumerable<YTCMS.Domain.Entities.products>
<div class="col-xs-12">
    <div class="row">
        <div class="col-xs-6">
            <h3 class="header smaller lighter blue"></h3>
            <div class="table-header">
                栏目线路
            </div>

            <div class="table-responsive">
                <div id="sample-table-2_wrapper" class="dataTables_wrapper" role="grid">
                    <div class="row">
                        <div class="col-sm-6">
                            <label>搜索: <input type="text" aria-controls="sample-table-2" id="txtpname2"></label>
                            <button type="button" id="btnSearch2" class="btn btn-purple btn-sm">
                                Search
                                <i class="icon-search icon-on-right bigger-110"></i>
                            </button>
                        </div>

                    </div>
                </div>
                <div id="shoudate2">
                    @Html.Partial("columnproduct", ViewData["cp"])
                </div>

            </div>
        </div>
        <div class="col-xs-6">
            <h3 class="header smaller lighter blue"></h3>
            <div class="table-header">
                选择线路
            </div>

            <div class="table-responsive">
                <div id="sample-table-2_wrapper" class="dataTables_wrapper" role="grid">
                    <div class="row">
                        <div class="col-sm-6">
                            <label>搜索: <input type="text" aria-controls="sample-table-2" id="txtpname"></label>
                            <button type="button" id="btnSearch" class="btn btn-purple btn-sm">
                                Search
                                <i class="icon-search icon-on-right bigger-110"></i>
                            </button>
                            <button class="btn btn-info btn-sm" type="button" id="btnSave">
                                <i class="icon-ok bigger-110"></i>
                                设置
                            </button>
                        </div>

                    </div>
                </div>
                <div id="shoudate1">
                    @Html.Partial("SetProductList", Model)
                </div>

            </div>
        </div>
    </div>
    
</div>

<script type="text/javascript">

    $(function(){
        $("#btnSave").click(function(){
            var pid = new Array();
            $("input[name='chk_product']:checked").each(function(){
                var that = $(this);
                var val = that.attr("value");
                pid.push(val);
                $.post("/Cmscolumn/SetColumnProduct",{pid:pid.toString(),cid:@ViewBag.cid },function(result){
                    if(result.d)
                    {
                        jAlert("设置成功","提示",function(){
                            window.location.href =window.location.href; 
                        });
                    }
                    else{
                        jAlert(result.msg,"提示");
                    }
                })
                
            });
        });

        $("a[name='edit']").click(function(){
            var that = $(this);
            var id = that.attr("value");
            var sort = that.parent().siblings(".sort");
            var val = sort.text();
            sort.empty().append("<input name='input_sort' value="+val+">");
            that.replaceWith("<a class='green' href='javascript:void(0)' title='保存' name='save' onclick='SaveOrder("+id+",this)'><i class='icon-edit bigger-120'></i>保存</a>")
        });

    })

    $("#btnSearch").click(function () {
        var con = new condition();

        $.btnClick({
            shoudate:"shoudate1",
            url: "/Cmscolumn/ProductSearch",
            data: { pname: con.pname }
        })
    });

    function SaveOrder(id,obj)
    {
        var that = $(obj);
        var sort = that.parent().siblings(".sort").find("[name='input_sort']").val();
        $.post("/Cmscolumn/SetOrder",{"id":id,"sort":sort},function(result){
            if(result.d)
            {
                jAlert("操作成功","提示",function(){window.location.href =window.location.href });
            }
            else{
                jAlert(result.msg,"提示");
            }
        })
    }

    function condition() {
        this.pname = $("#txtpname").val();
        return this;
    }

    function to_page(pageIndex) {
        var con = new condition();
        $.btnClick({
            url: "/Cmscolumn/ProductSearch",
            data: { pname: con.pname, pageIndex: pageIndex }
        })
    }


    $("#btnSearch2").click(function () {
        
        var con = new condition1();
 
        $.btnClick({
            shoudate:"shoudate2",
            url: "/Cmscolumn/columnproductSearch",
            data: { pname: con.pname,cid:con.cid }
        })
    });

    function condition1() {
        this.pname = $("#txtpname2").val();
        this.cid = @ViewBag.cid;
        return this;
    }

    function to_page1(pageIndex) {
        var con = new condition1();
        $.btnClick({
            shoudate:"shoudate2",
            url: "/Cmscolumn/columnproductSearch",
            data: { pname: con.pname,cid:con.cid, pageIndex: pageIndex }
        })
    }
</script>